package logic

import (
	"context"

	"rpc/wfw1/api/internal/svc"
	"rpc/wfw1/api/internal/types"
	"rpc/wfw1/rpc/returnage"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetageLogic {
	return &GetageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetageLogic) Getage(req *types.GetageReq) (resp *types.GetageResp, err error) {
	rpcResp, err := l.svcCtx.Returnage.Getage(l.ctx, &returnage.GetageReq{
		Name: req.Name,
	})
	if err != nil {
		return nil, err
	}

	return &types.GetageResp{
		Age: rpcResp.Age,
	}, nil
}
